package org.example.springboot3.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.springboot3.entity.Message;

import java.util.List;

@Mapper
public interface MessageMapper {

    Message selectById(Integer id);

    List<Message> selectAll(Message message);

    void addMessage(Message message);

    void deleteById(Integer id);


    void updateLikeCount(Message message);

    @Select("WITH RECURSIVE comment_tree AS ( " +
            "SELECT * FROM message WHERE parent_id IS NULL " +"UNION ALL " +
            "SELECT m.* FROM message m JOIN comment_tree ct ON m.parent_id = ct.id " +")"
            + "SELECT * FROM comment_tree ORDER BY id ASC")
    List<Message> selectAllMessagesWithHierarchy();
    
}//
